<template>
  <div class="app-container">
    <div class="filter-container">
      <div class="lineBox" style="font-size: 12px;color: #333;">
        【使用说明】本界面为一个独立程序，用于将大量类似“南京市人武部副部长”（A+B） 信息，全自动推理成-南京市人武部”（A）＋“副部长”(B)两部分，原理为通过B字典中
        “副部长”等一些初始值遍历所有A+B内容，推理出一批A字典值，再通过A字典推理出新的B字典，反复循环直到获得所有A、B的字典值，并完成信息组合的分离。
      </div>
      <el-form ref="dataForm" size="mini" :model="listQuery" label-position="right" label-width="auto">
        <div class="lineBox" style="display: flex;">
          <el-form-item label="处理对象：" prop="type">
            <el-select v-model="listQuery.type">
              <el-option label="头实体" value="1" />
              <el-option label="尾实体" value="2" />
            </el-select>
          </el-form-item>
          <el-form-item label="实体名称：" prop="entity_name" style="margin-left: 10px;">
            <el-input v-model="listQuery.entity_name" size="mini" placeholder="" style="width: 180px;" />
          </el-form-item>
        </div>
        <div class="lineBox" style="display: flex;">
          <el-form-item label="A字典：" prop="head_entity_name">
            <div style="display: flex;">
              <el-select v-model="listQuery.azd" style="width:100px;margin-left: 10px;">
                <el-option v-for="( itemDic ,indexDic ) in dictionaryType" :key="itemDic.key" :label="itemDic.label"
                  :value="itemDic.label" />
              </el-select>
              <label prop="head_entity_name" style="margin-left: 5px; width: 400px;">
                <span style="font-size: 12px;color: #333;font-weight: normal; margin-left: 10px;">剥离时加个条件：至少X个汉字：</span>
                <el-input-number v-model="listQuery.anum" :min="1" :max="10" label="描述文字" style="margin-left: 10px;"
                  @change="handleChange" />
              </label>
            </div>
          </el-form-item>
          <span
            style="align-content: center; margin-left:10px ; font-size: 12px;color: #333;">字符串中，A内容在前面，B在后面。无需初始值。</span>
        </div>

        <div class="lineBox" style="display: flex;">
          <el-form-item label="B字典：" prop="head_entity_name">
            <el-select v-model="listQuery.bzd" style="width:100px;margin-left: 10px;">
              <el-option v-for="( itemDic ,indexDic ) in dictionaryType" :key="itemDic.key" :label="itemDic.label"
                :value="itemDic.label" />
            </el-select>
            <label prop="head_entity_name" style="margin-left: 5px; width: 400px;">
              <span style="font-size: 12px;color: #333;font-weight: normal; margin-left: 10px;">剥离时加个条件：至少X个汉字：</span>
              <el-input-number v-model="listQuery.bnum" :min="1" :max="10" label="描述文字" style="margin-left: 10px;"
                @change="handleChange" />
            </label>
          </el-form-item>
          <span
            style="align-content: center; margin-left:10px ; font-size: 12px;color: #333;">【需要初始值】初始遍历从B字典开始，且同时匹配“部长”和“副部长〞两种字典值时，优先按字数多的。</span>
        </div>

        <div class="lineBox" style="display: flex;">
          <el-form-item label="循环次数" prop="num">
            <el-input-number v-model="listQuery.num" :min="1" :max="10" label="描述文字" @change="handleChange" />
          </el-form-item>
        </div>

        <div class="lineBox">
          <div class="lineBox">
            <el-button v-if="status==2" size="mini" type="primary" @click="startUp">
              启动
            </el-button>

            <el-button v-if="status==1" size="mini" type="danger" disabled="true">
              运行中
            </el-button>
          </div>
          <div class="lineBox">
            <el-button v-if="status==1" size="mini" style="margin-left: 10px;" type="primary" @click="cancel">
              取消
            </el-button>
          </div>
        </div>
      </el-form>
    </div>

    <div class="myTable" style="min-height: 600px;">
      <el-table :key="tableKey" :data="list" fit size="mini" highlight-current-row style="width: 100%;">
        <el-table-column label="ID" prop="id" align="center" width="50" />
        <el-table-column label="启动时间" prop="start_time" align="center" min-width="80" />
        <el-table-column label="结束时间" prop="end_time" align="center" min-width="80" />
        <el-table-column label="处理对象" prop="object_text" align="center" min-width="100" />
        <el-table-column label="处理数量" prop="files_num" align="center" min-width="100" />
        <el-table-column label="分离成功数" prop="files_num_succ" align="center" min-width="100" />
        <el-table-column label="前字典增加" prop="front_dictionary" align="center" min-width="100" />
        <el-table-column label="后字典增加" prop="after_dictionary" align="center" min-width="100" />
        <el-table-column label="操作" prop="create_time" align="center" min-width="100">
          <template slot-scope="{row,$index}">
            <el-button type="primary" size="mini" @click="skip(row,$index)">
              查看
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <pagination size="mini" :page-sizes="[10]" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit"
      layout="total, sizes, prev, pager, next, jumper" @pagination="getList" />
    <addNoticeDlg ref="addNoticeDlg" @getList="getList" />
  </div>
</template>

<script>
import { dicApi } from '@/api/dic'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import { dictionaryApi } from '@/api/dictionary'
export default {

  components: { Pagination },

  data() {
    return {
      status: "2",
      dictionaryType: [],
      formInline: {
        user: "",
        region: ""
      },
      value: '',

      tableKey: 0,
      list: [],
      total: 0,
      listLoading: false,
      listQuery: {
        pageNumber: 1,
        page: 1,
        limit: 10,
        type: "1",
        entity_name: "",
        rela_name: "",
        azd: "",
        bzd: "", //
        num: "",
        id: "",
        anum: "3",
        bnum: "2",

      },


    }
  },



  async created() {

    await this.getLastTask()
    await this.getAllDictionaryType()
    await this.getList()
  },
  methods: {

    async cancel() {

      const url = "cancel";
      const response = await dicApi(url, this.listQuery)

      if (response.code == 200) {


        this.status = 2;


        this.$message({
          message: '取消成功',
          type: 'success'
        });
      } else {
        this.$message({
          message: '取消失败',
          type: 'error'
        });
      }
    },


    async getLastTask() {
      const url = "getLastSeparate";
      const response = await dicApi(url, this.listQuery)
      if (response.code == 200) {

        if (response.data == "") {
          this.status = 2;
        } else {
          this.status = response.data.status
          this.listQuery.azd = response.data.object.azd;
          this.listQuery.bzd = response.data.object.bzd;
          this.listQuery.entity_name = response.data.object.entity_name;
          this.listQuery.type = response.data.object.type;
          this.listQuery.id = response.data.id
          this.listQuery.num = response.data.num
          // this.listQuery.anum = response.data.object.anum
          // this.listQuery.bnum = response.data.object.bnum

        }
      }
    },

    async startUp() {

      const url = "startUp";
      const response = await dicApi(url, this.listQuery)

      if (response.code == 200) {


        this.status = response.data.status
        this.listQuery.id = response.data.id


        this.$message({
          message: '启动成功',
          type: 'success'
        });
      } else {
        this.$message({
          message: '启动失败',
          type: 'error'
        });
      }


    },

    async getAllDictionaryType() {
      const url = 'getAllDictionaryType'
      var res = await dictionaryApi(url, {})
      if (res.code == 200) {
        this.dictionaryType = res.data;
      }

    },



    // 数据列表
    async getList() {
      this.listLoading = true
      const response = await dicApi("getTaskDicList", this.listQuery)
      if (response.code == 200) {
        this.list = response.data.resultList
        this.total = response.totalCount
        // this.type = response.type
        //   // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoading = false
        }, 1.5 * 1000)
      }
    },

    // 删除指标

    // 修改跳转
    async skip(row, index) {

      this.$router.push('/dictionary/stringseg?id=' + row.id)

    }
  }
}
</script>

<style lang="scss" scoped>
.demo-image__preview {
  float: left;
  margin-left: 5px;
}
.demonstration {
  font-size: 12px;
  color: #333;
  font-weight: normal;
}
</style>
